package com.edgelight.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
public class CheckcodeTools {
    @Value("${source}")
    private String source;
    public  String getCode(int len) {
        StringBuffer sb = new StringBuffer();
        Random r = new Random();
        System.out.println(source);
        for (int i = 0; i < len; i++) {
            int index = r.nextInt(source.length());
            System.out.println(index);
            sb.append(source.substring(index, index + 1));
        }
        return sb.toString();
    }
}
